package com.dapeng.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @author dapeng
 * @create 2020-10-03 14:26
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
public class jdbcConfig {

    @Value("jdbc.driver")
    String driverClassName;

    @Value("jdbc.url")
    String url;

    @Value("jdbc.username")
    String username;

    @Value("jdbc.password")
    String password;

    @Bean
    public DataSource dataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
